package com.zw.stock_sell_storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zw.stock_sell_storage.dto.LogDto;
import com.zw.stock_sell_storage.dto.MyPageDto;
import com.zw.stock_sell_storage.dto.ex.LogDtoEx;
import com.zw.stock_sell_storage.mapper.LogMapper;
import com.zw.stock_sell_storage.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, LogDto> implements ILogService {
    @Autowired
    LogMapper logMapper;
    @Override
    public Page<LogDto> queryLogList(MyPageDto<LogDtoEx> myPageDto) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (myPageDto.getData().getStartTime()!=null&&!"".equals(myPageDto.getData().getStartTime())){
            queryWrapper.ge("log_date",myPageDto.getData().getStartTime());
        }
        if (myPageDto.getData().getEndTime()!=null&&!"".equals(myPageDto.getData().getEndTime())){
            queryWrapper.le("log_date",myPageDto.getData().getEndTime());
        }
        return logMapper.selectPage(new Page<>(myPageDto.getCurrentPage(),myPageDto.getPageSize()),queryWrapper);
    }

    @Override
    @Transactional
    public boolean addLog(LogDto logDto) {
        logMapper.insert(logDto);
        return true;
    }
}
